package com.kaifamiao.www.demo.do0809;
public class Person implements Comparable{

    private String name;

    private int age;

    public String getName(){
        return name;
    }

    public void setName(String name){
        this.name = name;
    }
    public int getAge(){
        return age;
    }
    public void setAge(int age){
        this.age = age;
    }
    @Override
    public int compareTo(Object o) {
        if (o instanceof Person person){

        if(this.age - person.getAge()==0){
            return this.name.compareTo(person.name);
        }else{
            return this.age - person.age;
        }
      }
        return 0;
    }

    @Override
    public String toString(){
        return "Person{" + "name='" + name + '\'' + ",age" + age+'}';
    }
}
